package com.taiyi.renaissancemall.ui.classification.goodlist;

import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.taiyi.renaissancemall.R;
import com.taiyi.renaissancemall.bean.FindBrandListBean;

import java.util.ArrayList;
import java.util.List;

//展示筛选品牌
public class FindBrandListAdapter extends BaseQuickAdapter<FindBrandListBean.BrandlistBean, BaseViewHolder> {

    private GetFindBrandNameListener getFindBrandName;
    private List<String> str_ids = new ArrayList<>();

    public FindBrandListAdapter(int layoutResId, @Nullable List<FindBrandListBean.BrandlistBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, FindBrandListBean.BrandlistBean item) {
        TextView tv_find_brand = (TextView) helper.getView(R.id.tv_find_brand);
        tv_find_brand.setText(item.brandname);

        //记录已选和未选
        if (item.isChoose) {
            tv_find_brand.setSelected(true);
            str_ids.add(item.brandid + "");
        } else {
            tv_find_brand.setSelected(false);
            str_ids.remove(item.brandid + "");
        }

        tv_find_brand.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (tv_find_brand.isSelected()) {
                    tv_find_brand.setSelected(false);
                    str_ids.remove(item.brandid + "");
                    item.isChoose = false;
                } else {
                    tv_find_brand.setSelected(true);
                    str_ids.add(item.brandid + "");
                    item.isChoose = true;
                }
                //参数传递
                getFindBrandName.getFindBrandName(item.brandname, item.brandid, str_ids);
            }
        });
    }

    interface GetFindBrandNameListener {
        void getFindBrandName(String brandName, int brandId, List<String> ids);
    }

    void setOnGetFindBrandName(GetFindBrandNameListener getFindBrandName) {
        this.getFindBrandName = getFindBrandName;
    }

}
